package cn.swust.designpatternlearningplatform.dao;

import cn.swust.designpatternlearningplatform.dao.sql.TopicOptionDaoSql;
import cn.swust.designpatternlearningplatform.domain.bo.OptionsBo;
import cn.swust.designpatternlearningplatform.domain.dto.TopicDto;
import cn.swust.designpatternlearningplatform.domain.entity.TopicOption;
import org.apache.ibatis.annotations.*;

import java.util.Collection;
import java.util.List;

@Mapper
public interface TopicOptionDao {
    @Select("SELECT " +
            "id, topic_id, option_name, option_content, option_path " +
            "FROM topic_option " +
            "WHERE topic_id = #{topicId}")
    List<TopicOption> getOptionsOfTopic(@Param("topicId") Integer topicId);

    @Insert("insert into " +
            "topic_option(topic_id, option_name, option_content, option_path) " +
            "VALUES" +
            "(#{option.topicId},#{option.optionName}" +
            ",#{option.optionContent},#{option.optionPath})")
    Integer addOption(@Param("option") TopicOption topicOption);

    @Results(value = {
            @Result(property = "optionName", column = "option_name"),
            @Result(property = "optionContent", column = "option_content"),
            @Result(property = "optionContentPath", column = "option_path"),
    })
    @SelectProvider(value = TopicOptionDaoSql.class, method = "getTopicOptions")
    List<OptionsBo> getTopicOptions(Integer topicId);

    List<TopicOption> getByTopicIds(@Param("topicIds") Collection<Integer> topicIds);

    void deleteByTopicId(@Param("id") Integer topicId);

    /**
     * 根据题目id查询题目选项
     *
     * @param topicIds
     * @return java.util.List<cn.swust.designpatternlearningplatform.domain.dto.TopicDto>
     * @author Tang
     * @date 2023/10/12 17:25
     **/
    List<TopicDto> selectTopicOptionsByTopicIds(@Param("topicIds") Collection<Integer> topicIds);
}
